from business.base_token import BaseToken
import requests
from config.parseconfig import config_json_data


class UserManager(BaseToken):

    def __init__(self,secret=config_json_data['contact_secret']):
        super().__init__(secret)

    def get_department(self,id=None):
        params = {
            "access_token":self.token,
            "id":id
        }
        return requests.get('https://qyapi.weixin.qq.com/cgi-bin/department/list',params=params)

    def get_user(self,department_id,fetch_child=0):
        parmas = {
            "access_token":self.token,
            "department_id":department_id,
            "fetch_child":fetch_child
        }
        return requests.get('https://qyapi.weixin.qq.com/cgi-bin/user/simplelist',params=parmas)

if __name__ == '__main__':
    um = UserManager()
    r1 = um.get_department()
    # print(r1.json())
    id = r1.json()['department'][0]['id']
    print(id)
    r2 = um.get_user(department_id=id)
    print(r2.json())